﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Agile_E
{
    public partial class AddDealership : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.IsInRole("Manager"))
            {
                Response.Redirect("~/Denied.aspx");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Dealership newPlace = new Dealership();
            try
            {
                newPlace.ContactInformation.FirstName = txtname.Text;
                newPlace.Owner = txtowner.Text;
                newPlace.ContactInformation.Workphone = txtphone.Text;
                newPlace.ContactInformation.State = txtstate.Text;
                newPlace.ContactInformation.Zip = txtZip.Text;
                newPlace.ContactInformation.Address = txtstreet.Text;
                newPlace.ContactInformation.City = txtcity.Text;
                newPlace.Services = txtServices.Text;

                DatabaseHandler.connect();
                DatabaseHandler.addDealership(newPlace);
                ((Main)this.Master).writeStatus("Dealership added", false);
            }
            catch (Exception ex)
            {
                ((Main)this.Master).writeStatus(ex.Message, true);
            }
        }
    }
}
